package cn.achao.csr.api.factory;

import cn.achao.csr.api.SequenceApi;
import cn.achao.csr.base.utils.SnowflakeIdUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @Author: achao
 **/
@Slf4j
@Component
public class SequenceFallbackFactory implements FallbackFactory<SequenceApi> {
    @Override
    public SequenceApi create(Throwable throwable) {
        log.error("序列服务调用失败:{}", throwable.getMessage());
        return new SequenceApi() {
            @Override
            public Long getSegmentId(String key, String source) {
                return SnowflakeIdUtils.generateLId();
            }
        };
    }
}
